<template>
  <div class="hoteStockets">
    <h5>今日热点</h5>
    <van-swipe class="my-swipe" :autoplay="3000" indicator-color="skyblue">
      <van-swipe-item v-for="i in luboNum" :key="i">
        <van-grid column-num="3">
          <van-grid-item
            v-for="item in arrQuotes.slice((i - 1) * 3, i * 3)"
            :key="item.quote.code"
          >
            <h5>{{ item.quote.name }}</h5>
            <h5 :class="item.quote.chg > 0 ? 'orange' : 'green'">
              {{ item.quote.current }}
            </h5>
            <p :class="item.quote.chg > 0 ? 'orange' : 'green'">
              {{ item.quote.chg }} %
            </p>
          </van-grid-item>
        </van-grid>
      </van-swipe-item>
    </van-swipe>
  </div>
</template>

<script>
import * as api from "@/api/index.js";
export default {
  data() {
    return {
      arrQuotes: [],
    };
  },
  computed: {
    luboNum() {
      return Math.ceil(this.arrQuotes.length / 3);
    },
  },
  async mounted() {
    let res = await api.getQuotes();
    this.arrQuotes = res.data.items;
  },
};
</script>

<style lang="less" scoped>
.hoteStockets {
  /deep/ h5 {
    margin: 5px 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    width: 100%;
  }
  /deep/ p {
    margin: 5px 0;
    font-size: 0.4rem;
  }
  .green {
    color: green;
  }
  .orange {
    color: orange;
  }
  .van-grid-item {
    overflow: hidden;
  }
}
</style>
